package com.atguigu.day22.exer.codetest;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/28 14:36
 * @注释 写一段代码实现在遍历ArrayList时移除一个元素，例如：”java”？
 */
public class CodeTest11 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<String>();
        list.add("hello");
        list.add("java");
        list.add("world");

        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            if ("java".equals(next)) {
                iterator.remove();
            }
        }
        System.out.println(list);

    }
}
